package com.flashcash.solu.view.certification.presenter;

import com.flashcash.solu.bean.PersonalInfoServerBean;
import com.flashcash.solu.bean.ThirdPartDataBean;
import com.flashcash.solu.common.TokenManager;
import com.flashcash.solu.view.camera.FaceDetectorPreImpl;
import com.flashcash.solu.view.certification.FacebookAccountActView;

import okhttp3.ResponseBody;
import rx.Subscriber;
import rx.android.schedulers.AndroidSchedulers;
import rx.schedulers.Schedulers;

public class FacebookAccountActPresenterImp extends FaceDetectorPreImpl implements FacebookAccountActPresenter {

    @Override
    public void getPersonalInfo() {
        mUserApi.getPersonalInfo(TokenManager.getInstance().getToken())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribeOn(Schedulers.io())
                .subscribe(new Subscriber<PersonalInfoServerBean>() {
                    @Override
                    public void onCompleted() {

                    }

                    @Override
                    public void onError(Throwable e) {

                    }

                    @Override
                    public void onNext(PersonalInfoServerBean personalInfoServerBean) {
                        ((FacebookAccountActView) mView).setPersonalInfo(personalInfoServerBean);
                    }
                });
    }

    @Override
    public void getThirdPartAccount() {
        mUserApi.getThirdPartAccount(TokenManager.getInstance().getToken())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribeOn(Schedulers.io())
                .subscribe(new Subscriber<ThirdPartDataBean>() {
                    @Override
                    public void onCompleted() {

                    }

                    @Override
                    public void onError(Throwable e) {

                    }

                    @Override
                    public void onNext(ThirdPartDataBean thirdPartDataBean) {
                        if (thirdPartDataBean.getTypes() != null) {
                            for (String type : thirdPartDataBean.getTypes()) {
                                ((FacebookAccountActView) mView).changeStatus(type);
                            }
                        }
                    }
                });
    }

    @Override
    public void submitThirdPartData(String action, String dataChannel, String dataType, String taskId, String credentialNo, String realName, String mobile, String passbackparams) {
        mUserApi.submitThirdPartData(TokenManager.getInstance().getToken(),
                "TONGDUN", dataType, taskId, credentialNo, realName, mobile, "")
                .observeOn(AndroidSchedulers.mainThread())
                .subscribeOn(Schedulers.io())
                .subscribe(new Subscriber<ResponseBody>() {
                    @Override
                    public void onCompleted() {

                    }

                    @Override
                    public void onError(Throwable e) {

                    }

                    @Override
                    public void onNext(ResponseBody responseBody) {
                        ((FacebookAccountActView) mView).changeStatus(action);
                    }
                });
    }
}